package com.byt.framlib.commonwidget.bannerview.loader;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.byt.framlib.R;
import com.byt.framlib.baseapp.BaseApplication;


public class MyImageLoader extends ImageLoader {

    private int img = 0;

    public MyImageLoader() {

    }

    public MyImageLoader(int img) {
        this.img = img;
    }

    @Override
    public void displayImage(Context context, String path, ImageView imageView) {
        //具体方法内容自己去选择，次方法是为了减少banner过多的依赖第三方包，所以将这个权限开放给使用者去选择
        displayPE(imageView, path, img == 0 ? R.drawable.defalt_banner_img : img, img == 0 ? R.drawable.defalt_banner_img : img);

    }

    @Override
    public void displayImage(Context context, int resId, ImageView imageView) {
        display(imageView, resId);
    }

    private void display(ImageView imageView, int resid) {
        if (imageView == null) {
            throw new IllegalArgumentException("argument error");
        }
        Glide.with(BaseApplication.getAppContext())
                .load(resid)
                .placeholder(resid)
                .error(resid)
                .dontAnimate()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imageView);
    }

    //    @Override
//    public ImageView createImageView(Context context) {
//        //圆角
//        return new RoundAngleImageView(context);
//    }
    private void displayPE(ImageView imageView, String url, int placeholder, int error) {
        if (imageView == null) {
            throw new IllegalArgumentException("argument error");
        }
        Glide.with(BaseApplication.getAppContext())
                .load(url)
                .placeholder(placeholder)
                .error(error)
                .dontAnimate()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imageView);
    }

}
